/**
 *  Stream Recorder: Records RealPlayer(tm) streams as MP3s
 *  Copyright (C) 2007  David Griffiths
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package dg.radio2ipod.view;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 *
 * @author davidg
 */


/**
 * About box describing this application.
 */
public final class AboutBox extends JFrame implements ActionListener {
    private JLabel titleLabel;
    private JLabel[] aboutLabel;
    static final int LABEL_COUNT = 8;
    static final int ABOUT_WIDTH = 280;
    static final int ABOUT_HEIGHT = 230;
    static final int ABOUT_TOP = 200;
    static final int ABOUT_LEFT = 350;
    static final int BIG_FONT_SIZE = 14;
    static final int SMALL_FONT_SIZE = 14;
    static final int VERTICAL_MARGIN = 15;
    static final int HORIZONTAL_MARGIN = 15;
    private Font titleFont, bodyFont;
    private static ResourceBundle resBundle = ResourceBundle.getBundle(
            "dg/radio2ipod/resource/strings");

    public AboutBox() {
        super("");
        this.setResizable(false);
        SymWindow aSymWindow = new SymWindow();
        this.addWindowListener(aSymWindow);

        // Initialize useful fonts
        titleFont = new Font("Lucida Grande", Font.BOLD, BIG_FONT_SIZE);
        if (titleFont == null) {
            titleFont = new Font("SansSerif", Font.BOLD, BIG_FONT_SIZE);
        }
        bodyFont  = new Font("Lucida Grande", Font.PLAIN, SMALL_FONT_SIZE);
        if (bodyFont == null) {
            bodyFont = new Font("SansSerif", Font.PLAIN, SMALL_FONT_SIZE);
        }

        this.getContentPane().setLayout(new BorderLayout(HORIZONTAL_MARGIN,
                VERTICAL_MARGIN));

        aboutLabel = new JLabel[LABEL_COUNT];
        int count = 0;
        aboutLabel[count++] = new JLabel("");
        aboutLabel[count] = new JLabel(resBundle.getString("app.name"));
        aboutLabel[count++].setFont(titleFont);
        aboutLabel[count] = new JLabel(resBundle.getString("version"));
        aboutLabel[count++].setFont(bodyFont);
        aboutLabel[count++] = new JLabel("");
        aboutLabel[count++] = new JLabel("");
        aboutLabel[count] = new JLabel("JDK " + System.getProperty(
                "java.version"));
        aboutLabel[count++].setFont(bodyFont);
        aboutLabel[count] = new JLabel(resBundle.getString("copyright"));
        aboutLabel[count++].setFont(bodyFont);
        aboutLabel[count++] = new JLabel("");

        Panel textPanel2 = new Panel(new GridLayout(LABEL_COUNT, 1));
        for (int i = 0; i < LABEL_COUNT; i++) {
            aboutLabel[i].setHorizontalAlignment(JLabel.CENTER);
            textPanel2.add(aboutLabel[i]);
        }
        this.getContentPane().add(textPanel2, BorderLayout.CENTER);
        this.pack();
        this.setLocation(ABOUT_LEFT, ABOUT_TOP);
        this.setSize(ABOUT_WIDTH, ABOUT_HEIGHT);
    }

    class SymWindow extends java.awt.event.WindowAdapter {
        public void windowClosing(final java.awt.event.WindowEvent event) {
            setVisible(false);
        }
    }

    public void actionPerformed(final ActionEvent newEvent) {
        setVisible(false);
    }
}